package com.jeff;

import javax.swing.JFrame;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JLabel;

public class Win extends JFrame {

	private static final long serialVersionUID = 1L;
	private JTextField fieldName;
	private JTextArea textArea = new JTextArea();
	private JButton btnSend = new JButton("Send");
	private final JButton btnCancel = new JButton("cancel");
	private final JLabel lblNumber = new JLabel("Number");
	
	public Win() {
		super("Swing my class");
		getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));		
		getContentPane().add(lblNumber);		
		fieldName = new JTextField();
		fieldName.setColumns(10);
		getContentPane().add(fieldName);
		getContentPane().add(btnSend);
		textArea.setRows(5);
		textArea.setColumns(20);
		getContentPane().add(new JScrollPane(textArea));		
		getContentPane().add(btnCancel);
		this.setVisible(true);
		this.setBounds(100, 100, 297, 234);
		this.setUpEvents();
	}

	private void setUpEvents(){
		btnSend.addActionListener(new Click());
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		btnCancel.addActionListener(new Click());
	}
	class Click implements ActionListener {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			
			if(e.getSource() instanceof JButton && e.getActionCommand().equals("Send")) {
				textArea.append("\n"+e.getSource().getClass().getName());
				//JOptionPane.showMessageDialog(null, "yeah");
				String in = fieldName.getText();				
				//Number n = Double.parseDouble(in);
				//long d = Math.round(n.doubleValue());
				//String.valueOf(Double.isNaN(Double.parseDouble(in)))
				textArea.append(in.toString());
			} else {
				textArea.append("\n sup");
			}
		}
	}
	
	/*private String int2hex(int i) {
		
		String s = String.valueOf(i);
		
		int radix =5;
		
		int y = Integer.parseInt(s, radix);
		
		int x = Integer.valueOf(s, radix);
		
		float f = Float.valueOf(s.concat(String.valueOf(y)).concat(String.valueOf(x)));
		
		return Integer.toHexString(i+Integer.parseInt(String.valueOf(Math.ceil(f))));
	}*/
}
